const GET = 'GET';
const POST = 'POST';
const DELETE = 'DELETE';
import path from './path.js'
import cache from './token.js'
// // #ifdef MP-WEIXIN
// const envVersion = __wxConfig.envVersion;
// if (envVersion == 'develop') {
// 	// 测试版
// 	//var https = 'http://shufa';
// 	// var https = 'https://tuanwei.go.jokerfan.com/api';
// 	var https = 'https://jinghe.mini.go.jokerfan.com/api';
// } else if (envVersion == 'trial') {
// 	//体验版
// 	var https = 'https://jinghe.mini.go.jokerfan.com/api';

// } else if (envVersion == 'release') {
// 	//正式版
// 	var https = 'https://jinghe.mini.go.jokerfan.com/api';
// }
// // #endif

// // #ifdef H5
// if (process.env.NODE_ENV === 'development') {
// 	// var https = 'http://192.168.31.207/api';
// 	//var https = 'http://gongqingtuana.topcompete.com/api'
// 	var https =  'https://jinghe.mini.go.jokerfan.com/api'
// 	console.log('开发环境')
// } else {
// 	console.log('生产环境')
// 	var https = 'http://gongqingtuana.topcompete.com/api';
// }
// // #endif

function requestSync(method, url, data, val) {
	let that = this;
	return new Promise(function(resolve, reject) {
		// data请求内容进行统一的加密签名和token处理
		// console.log('token', cache.getCache('youthToken'))
		let header = {
			'content-type': 'application/json',
			'Authorization': 'bearer ' + cache.getCache('youthToken')
		};
		uni.request({
			url: path.apiUrl + url,
			method: method,
			data: method === POST ? JSON.stringify(data) : data,
			header: header,
			success: res => {
				if (res.data.code == 401) {
					console.log('提示登录')
				}
				if (res.statusCode == 200) {
					resolve(res);
				} else {
					uni.showToast({
						title: res.data.message,
						icon: 'none',
						duration: 3000
					})
					//其他异常
					return false;
				}
			},
			fail: err => {
				//请求失败
				reject(err);
			},
			complete: info => {}
		})

	})
}
const offer = {
	get_oss: () => requestSync(GET, '/common/oss')
}


module.exports = {
	offer: offer
}